// TokenSetView.cpp : implementation file
//

#include "stdafx.h"
#include "TokenSetViews.h"


// TokenSetView

TokenSetView::TokenSetView(CListCtrl*  LC, TokenSet* TS):
ListCtrl(LC), TSet(TS)
{
	ListCtrl->InsertColumn(0, _T("ID"),LVCFMT_LEFT,35,0);
	ListCtrl->InsertColumn(1, _T("Type"),LVCFMT_LEFT,75,0);
	ListCtrl->InsertColumn(2, _T("Complexity"),LVCFMT_LEFT,45,1);
	ListCtrl->InsertColumn(3, _T("Term"),LVCFMT_LEFT,2000,1);
}

void TokenSetView::ShowAll(){

		ListCtrl->DeleteAllItems();
		CString strText;
		size_t EltsNum = TSet->size();
		for(int i=0; i<EltsNum; i++){
			strText.Format(TEXT("%d"),i);
			ListCtrl->InsertItem(LVIF_TEXT|LVIF_STATE, i, strText,0,LVIS_SELECTED,0,0);
			try{
				Token::const_reference Temp= TSet->operator [](i);//getRandTerm(); 
				if(Temp.isTerm()) 
					ListCtrl->SetItemText(i,1,_T(_TERM(Temp).getType().toString().c_str()));
				else
					ListCtrl->SetItemText(i,1,_T("TYPE:"));
				strText.Format(TEXT("%d"),Temp.complexity());
				ListCtrl->SetItemText(i,2,strText);
				ListCtrl->SetItemText(i,3,_T(Temp.toString().c_str()));  
			}  catch(string err){
						ListCtrl->SetItemText(i,3,_T(err.c_str()));

				}
			}
	}

void TokenSetView::ShowTypes(){
		ListCtrl->DeleteAllItems();
		CString strText;
		for(int i=0; i<TSet->size(); i++){
			strText.Format(TEXT("%d"),i);
			ListCtrl->InsertItem(LVIF_TEXT|LVIF_STATE, i, strText,0,LVIS_SELECTED,0,0);
			try{
				Token::const_reference Temp= TSet->operator [](i);//getRandTerm(); 
				if(Temp.isType()){
					ListCtrl->SetItemText(i,1,_T("TYPE:"));
					strText.Format(TEXT("%d"),Temp.complexity());
					ListCtrl->SetItemText(i,2,strText);
					ListCtrl->SetItemText(i,3,_T(Temp.toString().c_str()));  
					}
				}
			catch(string err){
						ListCtrl->SetItemText(i,3,_T(err.c_str()));
				}
			}
	}

void TokenSetView::ShowTerms(){
		ListCtrl->DeleteAllItems();
		CString strText;
		for(size_t i=0; i<TSet->size(); i++){
			strText.Format(TEXT("%d"),i);
			ListCtrl->InsertItem(LVIF_TEXT|LVIF_STATE, i, strText,0,LVIS_SELECTED,0,0);
			try{
				Token::const_reference Temp= TSet->operator [](i);//getRandTerm(); 
				if(Temp.isTerm()){
					ListCtrl->SetItemText(i,1,_T(_TERM(Temp).getType().toString().c_str()));
					strText.Format(TEXT("%d"),Temp.complexity());
					ListCtrl->SetItemText(i,2,strText);
					ListCtrl->SetItemText(i,3,_T(Temp.view().c_str())); 
					}
				}  
			catch(string err){
						ListCtrl->SetItemText(i,3,_T(err.c_str()));
				}
			}
	 }


TokenSetView::~TokenSetView()
{
}


// TokenSetView member functions
